﻿#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include"game.h"

void menu()
{
	printf("****************************\n");
	printf("******1.paly    0.exit******\n");
	printf("****************************\n");
}

void game()
{
	char board[ROW][COL] = { 0 };		//创建棋盘
	InitBoard(board, ROW, COL);		//初始化棋盘
	DisplayBoard(board, ROW, COL);	//打印棋盘
	//   |   |   
	//---|---|---
	//   |   |   
	//---|---|---
	//   |   |   
	while (1)
	{
		int a = 0;
		PlayerMove(board, ROW, COL);
		DisplayBoard(board, ROW, COL);
		a = Judge(board, ROW, COL, WIN);
		switch (a)
		{
		case 1:
			printf("你赢了！\n");
			break;
		case 2:
			printf("你输了！\n");
			break;
		case 3:
			printf("平局！\n");
			break;
		case 4:
			break;
		}
		if (a != 4)
			break;
		ComputerMove(board, ROW, COL);
		DisplayBoard(board, ROW, COL);
		a = Judge(board, ROW, COL, WIN);
		switch (a)
		{
		case 1:
			printf("你赢了！\n");
			break;
		case 2:
			printf("你输了！\n");
			break;
		case 3:
			printf("平局！\n");
			break;
		case 4:
			break;
		}
		if (a != 4)
			break;
	}
}

void test()
{
	int input = 0;
	do
	{
		menu();
		printf("请选择:>");
		scanf("%d", &input);
		switch (input)
		{
		case 1:
			game();
			break;
		case 0:
			printf("退出游戏\n");
			break;
		default:
			printf("选择错误，请重新选择\n");
			break;
		}
	} while (input);
}

int main()
{
	test();
	return 0;
}